#include "FiveWin.ch"

static lRegistered := .f.

//----------------------------------------------------------------------------//

CLASS TMdiFrame FROM TWindow

   DATA   oWndClient, oWndActive
   DATA   nMenuPos

   METHOD New( nTop, nLeft, nBottom, nRight, cTitle, nStyle, oMenu ) CONSTRUCTOR
   METHOD ChildNew( nTop, nLeft, nBottom, nRight, cTitle, nStyle ) BLOCK ;
       { | Self, nTop, nLeft, nBottom, nRight, cTitle, nStyle | ;
       ::oWndClient:ChildNew( nTop, nLeft, nBottom, nRight, cTitle, nStyle ) }
   METHOD Cascade()      BLOCK { | Self | ::oWndClient:Cascade() }
   METHOD Tile()         BLOCK { | Self | ::oWndClient:Tile() }
   METHOD ArrangeIcons() BLOCK { | Self | ::oWndClient:ArrangeIcons() }
   METHOD NextWindow()   BLOCK { | Self | ::oWndClient:NextWindow() }
   METHOD Release()
   METHOD ReSize( nSizeType, nWidth, nHeight )

ENDCLASS

//----------------------------------------------------------------------------//

METHOD New( nTop, nLeft, nBottom, nRight, cTitle, nStyle, oMenu ) CLASS TMdiFrame

   DEFAULT nStyle := nOR( WS_OVERLAPPEDWINDOW, WS_CLIPCHILDREN )

   ::nTop     = nTop    * 16
   ::nLeft    = nLeft   *  8
   ::nBottom  = nBottom * 16
   ::nRight   = nRight  *  8
   ::nStyle   = nStyle
   ::cCaption = cTitle
   ::nId      = 0

   if oMenu == nil
      MENU oMenu
         MENUITEM "&File"
         MENU
            MENUITEM "New &File"       ACTION ::ChildNew( 20, 20, 100, 200 )
            SEPARATOR
            MENUITEM "E&xit"           ACTION ::End()
         ENDMENU
         MENUITEM "&Window"
         MENU
            MENUITEM "&Tile"           ACTION ::Tile()
            MENUITEM "&Cascade"        ACTION ::Cascade()
            MENUITEM "&Next Window"    ACTION ::NextWindow()
            MENUITEM "&Arrange Icons"  ACTION ::ArrangeIcons()
            MENUITEM "&Close All"      ACTION ::CloseAll()
         ENDMENU
      ENDMENU
   endif

   if ! lRegistered
      RegisterClass( ::ClassName(),;
                     nOR( CS_VREDRAW, CS_HREDRAW ),;
                     0, 0, 0, 0, 0, "", GetFrameProc() )
      lRegistered = .t.
   endif

   ::Create()
   ::SetMenu( oMenu )
   ::oWndClient = TMdiClient():New( Self, 1, 1 )  // SubMenu, nChild

return

//----------------------------------------------------------------------------//

METHOD Release() CLASS TMdiFrame

   ::UnLink()

   if GetProp( ::hWnd, "WP" ) == 1
      PostQuitMessage( 0 )
   endif

return

//----------------------------------------------------------------------------//

METHOD ReSize( nSizeType, nWidth, nHeight ) CLASS TMdiFrame

   if ::oWndClient != nil
      ::oWndClient:Move( If( ::oBar != nil, 29, 0 ),;
                         0, nWidth,;
                         nHeight - ;
                         If( ::oBar != nil, 27, 0 ) - ;
                         If( ::oMsgBar != nil, 27, 0 ), .t. )
   endif

   Super:ReSize( nSizeType, nWidth, nHeight )

return 0

//----------------------------------------------------------------------------//
